﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using PaperRenderingInterfaces;
using System.IO;

namespace t_PivotGeneratorTestHelpers
{
    /// <summary>
    /// Load a file instead of accessing the web.
    /// </summary>
    [Export(typeof(IWebAccess))]
    public class LoadAFile : IWebAccess
    {
        public FileInfo theFileToLoad;
        public string UrlAskedFor { get; set; }

        public string GetUriAsString(Uri whatToLoad)
        {
            UrlAskedFor = whatToLoad.OriginalString;

            return LoadFile(theFileToLoad);
        }

        /// <summary>
        /// Load up the req' file.
        /// </summary>
        /// <param name="finfo"></param>
        /// <returns></returns>
        private string LoadFile(FileInfo finfo)
        {
            if (finfo.Exists)
            {
                using (var reader = finfo.OpenText())
                {
                    return reader.ReadToEnd();
                }
            }
            else
            {
                return null;
            }
        }

        public DateTime DateToReturn = DateTime.Now - new TimeSpan(12, 0, 0);

        public DateTime? GetLastModificationTime(Uri whatToCheck)
        {
            return DateToReturn;
        }
    }
}
